#include "catch.hpp"
#include "coherentElastic/coherentElastic_util/hexLatticeFactors.h"
#include "generalTools/testing.h"

TEST_CASE( "tausq" ){
  GIVEN( "inputs" ){
    std::vector<std::tuple<int,int,int,double,double>> inputs
      { {0,0,0,2,4}, {1,0,0,2,4}, {0,1,0,2,4}, {0,0,1,2,4}, {1,1,0,2,4}, 
        {1,0,1,2,4}, {0,1,1,2,4}, {1,1,1,2,4}, {1,2,3,4,5}, {5,3,6,4,5},
        {8,7,9,.1,.2} };
    std::vector<double> correct { 0, 78.956835, 78.956835, 157.91367041, 
    236.870505, 236.870505, 236.870505, 394.78417604, 2881.924485, 
    14843.885019, 1306.735642 };
    
    for ( size_t i = 0; i < inputs.size(); ++i ){
      auto output = tausq(std::get<0>(inputs[i]),std::get<1>(inputs[i]),
                          std::get<2>(inputs[i]),std::get<3>(inputs[i]),
                          std::get<4>(inputs[i]));
      REQUIRE( correct[i] == Approx(output).epsilon(1e-6) );
    }
  } // GIVEN
} // TEST CASE




TEST_CASE( "Function to Compute Hexagonal Lattice Factors" ){
  int k;
  double tsq, tsqx, f;
  std::vector<double> b ( 60000, 0.0 );

  k = 0; 

  GIVEN( "k is not positive or tsq <= tsqx" ){
    tsq = 0.1; tsqx = 9.6;
    THEN( "b's first two entries are populted with tsq and f, respectively" ){
 
      std::vector<double> fVec {3.0, 100, 100}, tsqVec {0.1, 0.1, 50};
      std::vector<std::tuple<double,double,double>> 
        good {{0.1,3.0,1},{0.1,100,1},{50,100,1}};

      for ( size_t j = 0; j < 3; ++j ){
        tsq = tsqVec[j]; f = fVec[j]; k = 0;
        hexLatticeFactorsHelper( k, tsq, tsqx, b, f );
        REQUIRE( b[0] == Approx(std::get<0>(good[j])).epsilon(1e-6) );
        REQUIRE( b[1] == Approx(std::get<1>(good[j])).epsilon(1e-6) );
        REQUIRE( k    == Approx(std::get<2>(good[j])).epsilon(1e-6) );
        restAreZero(2,b);
      } 
    } // THEN
  } // GIVEN

  GIVEN( "k is positive and tsq > tsqx" ){
    WHEN( "loop is able to finish" ){
      THEN( "we're in the 2st situation, f goes in b (only 1 val added)" ){

        std::vector<double> 
          fVec    {0.045, 1.5, 0.45}, tsqVec {30.1,10.1,60.1}, 
          tsqxVec {25.0,    5,   15}, kVec   {2.0,    1,   2};
	    std::vector<std::vector<double>> correct_b{ {10,20,30,40.045,0,0}, 
          {10,21.5,30,40,0,0}, {10,20,30,40,60.1,0.45} };

        for ( size_t j = 0; j < 3; ++j ){
          tsq = tsqVec[j]; tsqx = tsqxVec[j]; f = fVec[j]; k = kVec[j];
          b[0] = 10; b[1] = 20; b[2] = 30; b[3] = 40;
          hexLatticeFactorsHelper( k, tsq, tsqx, b, f );
          for ( size_t i = 0; i < correct_b[j].size(); ++i ){ 
            REQUIRE( b[i] == Approx(correct_b[j][i]).epsilon(1e-6) );
          }
          restAreZero(correct_b[j].size(),b);
        } 
      } // THEN
    } // WHEN
    
    WHEN( "loop isn't able to finish" ){
      THEN( "we're in the second situation" ){
        tsq = 700, tsqx = 500;
        k = 1; f = 4.5e-2;
        hexLatticeFactorsHelper( k, tsq, tsqx, b, f );

        REQUIRE( b[0] == Approx(0).epsilon(1e-6) ); 
        REQUIRE( b[1] == Approx(0).epsilon(1e-6) ); 
        REQUIRE( b[2] == Approx(700).epsilon(1e-6) ); 
        REQUIRE( b[3] == Approx(4.5e-2).epsilon(1e-6) ); 
        REQUIRE( k == Approx(2).epsilon(1e-6) ); 
        restAreZero(4,b);

        tsq = 63, tsqx = 50;
        k = 1; f = 1.5;
        b[0] = 10; b[1] = 20; b[2] = 30; b[3] = 40; b[4] = 50; b[5] = 60;
        hexLatticeFactorsHelper( k, tsq, tsqx, b, f );

        REQUIRE( b[0] == Approx(10).epsilon(1e-6) ); 
        REQUIRE( b[1] == Approx(20).epsilon(1e-6) ); 
        REQUIRE( b[2] == Approx(63).epsilon(1e-6) ); 
        REQUIRE( b[3] == Approx(1.5).epsilon(1e-6) ); 
        REQUIRE( b[4] == Approx(50).epsilon(1e-6) ); 
        REQUIRE( b[5] == Approx(60).epsilon(1e-6) );
        REQUIRE( k == Approx(2).epsilon(1e-6) ); 
        restAreZero(6,b);
      } // THEN
    } // WHEN
  } // GIVEN
} // TEST CASE








TEST_CASE( "Function to Compute Hex Lattice Factors" ){
  std::vector<double> b (60000, 0.0);
  std::vector<double> bVec1(100), bVec2(100);
  int lat, imax;
  double a, c;
  double maxTauSq;

  GIVEN( "input material is graphite" ){
    lat = 1;
    a = 2.4573e-8, c = 6.7e-8;

    WHEN( "max energy of 3eV is used" ){
      maxTauSq = 5.79115688E19; // this corresponds with Emax = 3eV
      imax = hexLatticeFactors( lat, a, c, maxTauSq, b );
      REQUIRE( imax == 376 );
      bVec1 = { 8.794479E15, 0.000000000, 8.794479E15, 0.000000000, 3.517792E16, 
                2.132676E-8, 3.517792E16, 2.132676E-8, 7.915031E16, 0.000000000, 
                7.915031E16, 0.000000000, 1.407117E17, 1.066338E-8, 1.407117E17, 
                1.066338E-8, 2.198620E17, 0.000000000, 2.198620E17, 0.000000000, 
                3.166013E17, 7.108921E-9, 3.166013E17, 7.108921E-9, 4.309295E17, 
                0.000000000, 4.309295E17, 0.000000000, 5.628467E17, 5.331691E-9, 
                5.628467E17, 5.331691E-9, 7.123528E17, 0.000000000, 7.123528E17, 
                0.000000000, 8.794479E17, 4.265352E-9, 8.794479E17, 4.265352E-9, 
                1.064132E18, 9.190335E-8, 1.266405E18, 2.807657E-8, 1.486267E18, 
                4.616903E-8, 1.723718E18, 2.423292E-8, 1.978758E18, 8.015864E-8, 
                2.251387E18, 7.427623E-8, 2.541605E18, 5.189872E-8, 2.849411E18, 
                8.224307E-8, 3.174807E18, 1.228114E-7, 3.517792E18, 2.038626E-7, 
                3.878365E18, 1.493290E-7, 4.256528E18, 1.992263E-7, 4.652280E18, 
                2.096901E-7, 5.065620E18, 2.298167E-7, 5.496550E18, 2.552567E-7, 
                5.945068E18, 2.437472E-7, 6.411175E18, 2.508482E-7, 6.894872E18, 
                3.766880E-7, 7.396157E18, 3.081091E-7, 7.915031E18, 3.459003E-7, 
                8.451495E18, 3.404497E-7, 9.005547E18, 4.095240E-7, 9.577188E18, 
                4.905315E-7, 1.016642E19, 4.686825E-7, 1.077324E19, 4.824778E-7, 
                1.139765E19, 5.055949E-7, 1.203964E19, 5.129935E-7, 1.269923E19, 
                6.136718E-7, 1.337640E19, 6.237878E-7, 1.407117E19, 5.888753E-7};
      bVec2 = { 1.140967E18, 6.178052E-8, 4.139884E18, 1.68910E-34, 5.327139E18, 
                2.079669E-8, 2.224772E19, 4.195626E-8, 6.102112E17, 1.280147E-9, 
                2.615191E17, 3.128732E-8, 6.190056E17, 7.626125E-9, 2.703136E17, 
                6.61024E-34, 6.453891E17, 2.489540E-9, 2.966970E17, 5.874804E-8, 
                6.893615E17, 7.226496E-9, 3.406694E17, 5.88822E-34, 7.509228E17, 
                2.307982E-9, 4.022307E17, 5.045595E-8, 8.300732E17, 6.585565E-9, 
                4.813811E17, 4.95343E-34, 9.268124E17, 2.077467E-9, 5.781203E17, 
                4.208631E-8, 1.041141E18, 4.110627E-8, 6.924486E17, 4.13007E-34, 
                8.243657E17, 3.524439E-8, 2.096478E18, 1.243161E-8, 4.128003E18, 
                2.953121E-9, 4.488577E18, 8.496072E-9, 1.264985E19, 2.192000E-8, 
                3.019484E19, 2.947148E-8, 1.133249E18, 2.818114E-9, 6.102112E17, 
                1.280147E-9, 6.190056E17, 7.626125E-9, 6.453891E17, 2.489540E-9, 
                1.212400E18, 1.634743E-8, 6.893615E17, 7.226496E-9, 7.509228E17, 
                2.307982E-9, 8.300732E17, 6.585565E-9, 9.268124E17, 2.077467E-9, 
                1.564179E18, 1.439227E-8, 5.785529E18, 7.483435E-9, 1.909784E18, 
                3.459129E-8, 2.393480E18, 6.205208E-8, 2.710081E18, 8.378648E-8, 
                4.082020E18, 5.047676E-8, 2.702364E18, 1.824943E-9, 3.018965E18, 
                3.453204E-9, 7.767984E18, 2.152767E-9, 7.243079E18, 2.229408E-9, 
                8.905235E18, 6.031840E-9, 2.043480E19, 1.327291E-9, 3.014390E19, 
                2.604521E-8, 5.195421E19, 1.747702E-8, 1.870598E19, 1.426956E-7};
      checkPartOfVec(b,bVec1,0);
      checkPartOfVec(b,bVec2,500);
      restAreZero(755,b);

    } // WHEN


    WHEN( "max energy of 5eV is used" ){
      maxTauSq = 9.65192813E19; // this corresponds with Emax = 5eV
      imax = hexLatticeFactors( lat, a, c, maxTauSq, b );
      REQUIRE( imax == 424 );
      bVec1 = { 8.794479E15, 0.000000000, 8.794479E15, 0.000000000, 3.517792E16, 
                2.132676E-8, 3.517792E16, 2.132676E-8, 7.915031E16, 0.000000000, 
                7.915031E16, 0.000000000, 1.407117E17, 1.066338E-8, 1.407117E17, 
                1.066338E-8, 2.198620E17, 0.000000000, 2.198620E17, 0.000000000, 
                3.166013E17, 7.108921E-9, 3.166013E17, 7.108921E-9, 4.309295E17, 
                0.000000000, 4.309295E17, 0.000000000, 5.628467E17, 5.331691E-9, 
                5.628467E17, 5.331691E-9, 7.123528E17, 0.000000000, 7.123528E17, 
                0.000000000, 8.794479E17, 4.265352E-9, 8.794479E17, 4.265352E-9, 
                1.064132E18, 9.190335E-8, 1.266405E18, 2.807657E-8, 1.486267E18, 
                4.616903E-8, 1.723718E18, 2.423292E-8, 1.978758E18, 8.015864E-8, 
                2.251387E18, 7.427623E-8, 2.541605E18, 5.189872E-8, 2.849411E18, 
                8.224307E-8, 3.174807E18, 1.228114E-7, 3.517792E18, 2.038626E-7, 
                3.878365E18, 1.493290E-7, 4.256528E18, 1.992263E-7, 4.652280E18, 
                2.096901E-7, 5.065620E18, 2.298167E-7, 5.496550E18, 2.552567E-7, 
                5.945068E18, 2.437472E-7, 6.411175E18, 2.508482E-7, 6.894872E18, 
                3.766880E-7, 7.396157E18, 3.081091E-7, 7.915031E18, 3.459003E-7, 
                8.451495E18, 3.404497E-7, 9.005547E18, 4.095240E-7, 9.577188E18, 
                4.905315E-7, 1.016642E19, 4.686825E-7, 1.077324E19, 4.824778E-7, 
                1.139765E19, 5.055949E-7, 1.203964E19, 5.129935E-7, 1.269923E19, 
                6.136718E-7, 1.337640E19, 6.237878E-7, 1.407117E19, 5.888753E-7};
      bVec2 = { 4.935960E19, 6.831119E-9, 9.634851E19, 5.592003E-8, 3.218181E19, 
                4.759469E-9, 4.927828E19, 6.323328E-8, 9.060354E19, 1.376567E-7, 
                4.921654E19, 6.839470E-8, 9.058577E19, 1.355315E-8, 9.614388E19, 
                1.168044E-7, 7.491600E19, 4.331495E-8, 6.989480E19, 1.485044E-7, 
                7.491535E19, 7.62372E-33, 8.511695E19, 4.746772E-8, 5.765795E19, 
                9.876488E-9, 9.050533E19, 1.075002E-7, 9.608564E19, 6.640196E-8, 
                7.479878E19, 1.310436E-7, 2.615191E17, 1.564366E-8, 8.717302E16, 
                1.693476E-9, 2.703136E17, 0.000000E00, 9.596750E16, 9.684098E-9, 
                2.966970E17, 2.937402E-8, 1.223509E17, 2.858883E-9, 3.406694E17, 
                0.000000E00, 1.663233E17, 7.356050E-9, 4.022307E17, 2.522797E-8, 
                2.278847E17, 2.094799E-9, 4.813811E17, 0.000000E00, 3.070350E17, 
                5.414113E-9, 5.781203E17, 2.104316E-8, 4.037743E17, 1.573732E-9, 
                6.924486E17, 0.000000E00, 5.181025E17, 4.167863E-9, 8.243657E17, 
                1.762220E-8, 6.500197E17, 1.240329E-9, 7.995258E17, 3.355096E-9, 
                1.140967E18, 6.178052E-8, 4.139884E18, 1.68910E-34, 5.327139E18, 
                2.079669E-8, 2.224772E19, 4.195626E-8, 6.102112E17, 1.280147E-9, 
                2.615191E17, 3.128732E-8, 6.190056E17, 7.626125E-9, 2.703136E17, 
                6.61024E-34, 6.453891E17, 2.489540E-9, 2.966970E17, 5.874804E-8, 
                6.893615E17, 7.226496E-9, 3.406694E17, 5.88822E-34, 7.509228E17, 
                2.307982E-9, 4.022307E17, 5.045595E-8, 8.300732E17, 6.585565E-9};
      checkPartOfVec(b,bVec1,0);
      checkPartOfVec(b,bVec2,500);
      restAreZero(851,b);
    } // WHEN
  } // GIVEN


  GIVEN( "input material is beryllium metal" ){
    lat = 2;
    a = 2.2856e-8, c = 3.5832e-8;
    WHEN( "max energy of 3eV is used" ){
      maxTauSq = 5.79115688E19; // this corresponds with Emax = 3eV
      imax = hexLatticeFactors( lat, a, c, maxTauSq, b );
      REQUIRE( imax == 257);
      bVec1 = { 3.074805E16, 0.000000000, 3.074805E16, 0.000000000, 1.229922E17, 
                5.702840E-9, 1.229922E17, 5.702840E-9, 2.767325E17, 0.000000000, 
                2.767325E17, 0.000000000, 4.919689E17, 2.851420E-9, 4.919689E17, 
                2.851420E-9, 7.687014E17, 0.000000000, 7.687014E17, 0.000000000, 
                1.106930E18, 3.801893E-9, 1.506655E18, 4.882765E-9, 1.967875E18, 
                2.817066E-8, 2.490592E18, 5.406715E-8, 3.074805E18, 1.336875E-7, 
                3.720515E18, 1.106346E-7, 4.427720E18, 6.371213E-8, 5.196421E18, 
                1.277608E-7, 6.026619E18, 8.597849E-8, 6.918312E18, 1.081190E-7, 
                7.871502E18, 1.955461E-7, 8.886188E18, 1.608812E-7, 9.962370E18, 
                2.029706E-7, 1.110005E19, 2.315955E-7, 1.229922E19, 2.674935E-7, 
                1.355989E19, 3.204105E-7, 1.488206E19, 3.255144E-7, 1.626572E19, 
                2.903753E-7, 1.771088E19, 3.560400E-7, 1.921753E19, 3.775424E-7, 
                2.078568E19, 4.430531E-7, 2.241533E19, 4.891875E-7, 2.410647E19, 
                4.953356E-7, 2.585911E19, 5.593328E-7, 2.767325E19, 5.611698E-7, 
                2.954888E19, 6.039650E-7, 3.148601E19, 6.292359E-7, 3.348463E19, 
                6.598955E-7, 3.554475E19, 7.274757E-7, 3.766637E19, 7.501291E-7, 
                3.984948E19, 7.887896E-7, 4.209409E19, 8.742202E-7, 4.440019E19, 
                9.036626E-7, 4.676779E19, 9.692886E-7, 4.919689E19, 1.010821E-6, 
                5.168748E19, 1.043008E-6, 5.685315E19, 4.531666E-7, 1.007623E17, 
                3.150293E-9, 1.007623E17, 3.150293E-9, 1.315103E17, 1.654517E-8}; 
      bVec2 = { 4.919110E19, 4.277327E-9, 3.022869E17, 7.275291E-9, 1.007623E17, 
                3.150293E-9, 3.330349E17, 0.000000000, 1.315103E17, 1.654517E-8, 
                4.252791E17, 1.226741E-8, 2.237545E17, 4.228089E-9, 5.790194E17, 
                0.000000000, 3.774948E17, 9.765529E-9, 7.942557E17, 8.976557E-9, 
                5.927312E17, 2.597773E-9, 8.694636E17, 6.434659E-9, 2.270162E18, 
                3.169890E-8, 5.498708E18, 1.532766E-8, 6.328905E18, 4.279837E-8, 
                7.053360E17, 2.381398E-9, 3.022869E17, 1.455058E-8, 7.360841E17, 
                1.398677E-8, 3.330349E17, 0.000000000, 8.283282E17, 4.394999E-9, 
                4.252791E17, 2.453483E-8, 5.790194E17, 0.000000000, 7.942557E17, 
                1.795311E-8, 1.474037E18, 2.965161E-8, 2.211991E18, 5.628383E-8, 
                5.133056E18, 5.296552E-9, 5.901757E18, 3.934990E-8, 1.180538E19, 
                1.047762E-8, 1.426523E19, 4.127853E-8, 1.309910E18, 5.712796E-8, 
                7.053360E17, 2.381398E-9, 7.360841E17, 1.398677E-8, 8.283282E17, 
                4.394999E-9, 1.586642E18, 2.858005E-8, 3.277785E18, 6.628130E-9, 
                4.384715E18, 5.730738E-9, 2.209559E19, 3.571212E-8, 2.541638E19, 
                6.650904E-8, 2.716902E19, 3.681865E-8, 7.312429E18, 0.000000000, 
                1.567590E19, 3.331131E-8, 4.421009E19, 2.706785E-9, 3.246623E18, 
                6.659863E-9, 5.091506E18, 2.125688E-8, 4.332778E18, 2.011640E-8, 
                8.760498E18, 8.107608E-9, 2.204366E19, 2.298933E-8, 2.355031E19, 
                4.200346E-8, 7.711326E18, 1.728529E-8, 1.177007E19, 4.194607E-8};
      checkPartOfVec(b,bVec1,0);
      checkPartOfVec(b,bVec2,300);
      restAreZero(517,b);

    } // WHEN


    WHEN( "max energy of 5eV is used" ){
      maxTauSq = 9.65192813E19; // this corresponds with Emax = 5eV
      imax = hexLatticeFactors( lat, a, c, maxTauSq, b );
      REQUIRE( imax == 294 );
      bVec1 = {3.074805E16, 0.000000000, 3.074805E16, 0.000000000, 1.229922E17, 
               5.702840E-9, 1.229922E17, 5.702840E-9, 2.767325E17, 0.000000000, 
               2.767325E17, 0.000000000, 4.919689E17, 2.851420E-9, 4.919689E17, 
               2.851420E-9, 7.687014E17, 0.000000000, 7.687014E17, 0.000000000, 
               1.106930E18, 3.801893E-9, 1.506655E18, 4.882765E-9, 1.967875E18, 
               2.817066E-8, 2.490592E18, 5.406715E-8, 3.074805E18, 1.336875E-7, 
               3.720515E18, 1.106346E-7, 4.427720E18, 6.371213E-8, 5.196421E18, 
               1.277608E-7, 6.026619E18, 8.597849E-8, 6.918312E18, 1.081190E-7, 
               7.871502E18, 1.955461E-7, 8.886188E18, 1.608812E-7, 9.962370E18, 
               2.029706E-7, 1.110005E19, 2.315955E-7, 1.229922E19, 2.674935E-7, 
               1.355989E19, 3.204105E-7, 1.488206E19, 3.255144E-7, 1.626572E19, 
               2.903753E-7, 1.771088E19, 3.560400E-7, 1.921753E19, 3.775424E-7, 
               2.078568E19, 4.430531E-7, 2.241533E19, 4.891875E-7, 2.410647E19, 
               4.953356E-7, 2.585911E19, 5.593328E-7, 2.767325E19, 5.611698E-7, 
               2.954888E19, 6.039650E-7, 3.148601E19, 6.292359E-7, 3.348463E19, 
               6.598955E-7, 3.554475E19, 7.274757E-7, 3.766637E19, 7.501291E-7, 
               3.984948E19, 7.887896E-7, 4.209409E19, 8.742202E-7, 4.440019E19, 
               9.036626E-7, 4.676779E19, 9.692886E-7, 4.919689E19, 1.010821E-6, 
               5.168748E19, 1.043008E-6, 5.685315E19, 1.197387E-6, 6.226481E19, 
               1.332173E-6, 6.792245E19, 1.411565E-6, 7.382608E19, 1.482589E-6 };
      bVec2 = {2.237545E19, 1.395034E-8, 2.363612E19, 1.253039E-7, 3.962511E19, 
               8.578010E-9, 1.296094E19, 6.809194E-8, 2.215461E19, 7.757721E-8, 
               5.428632E19, 2.198066E-8, 2.560982E19, 1.895579E-8, 3.529545E19, 
               1.451950E-7, 7.136292E19, 5.111142E-8, 1.715182E19, 4.346277E-9, 
               9.085490E19, 1.747945E-7, 3.746029E19, 9.496766E-8, 4.188905E19, 
               3.520946E-8, 2.912030E19, 4.495746E-8, 3.108818E19, 3.764766E-8, 
               3.956529E19, 2.860745E-8, 4.424669E19, 5.678223E-8, 4.919110E19, 
               4.277327E-9, 9.076770E19, 3.211074E-8, 9.071681E19, 1.511712E-8, 
               3.022869E17, 7.275291E-9, 1.007623E17, 3.150293E-9, 3.330349E17, 
               0.000000000, 1.315103E17, 1.654517E-8, 4.252791E17, 1.226741E-8, 
               2.237545E17, 4.228089E-9, 5.790194E17, 0.000000000, 3.774948E17, 
               9.765529E-9, 7.942557E17, 8.976557E-9, 5.927312E17, 2.597773E-9, 
               8.694636E17, 6.434659E-9, 2.270162E18, 3.169890E-8, 5.498708E18, 
               1.532766E-8, 6.328905E18, 4.279837E-8, 5.983052E19, 6.205273E-9, 
               7.053360E17, 2.381398E-9, 3.022869E17, 1.455058E-8, 7.360841E17, 
               1.398677E-8, 3.330349E17, 0.000000000, 8.283282E17, 4.394999E-9, 
               4.252791E17, 2.453483E-8, 5.790194E17, 0.000000000, 7.942557E17, 
               1.795311E-8, 1.474037E18, 2.965161E-8, 2.211991E18, 5.628383E-8, 
               5.133056E18, 5.296552E-9, 5.901757E18, 3.934990E-8, 1.180538E19, 
               1.047762E-8, 1.426523E19, 4.127853E-8, 7.757547E19, 9.529087E-8};
      checkPartOfVec(b,bVec1,0);
      checkPartOfVec(b,bVec2,300);
      restAreZero(591,b);
    } // WHEN
  } // GIVEN

  GIVEN( "input material is beryllium in beryllium oxide" ){
    lat = 3;
    a = 2.695e-8, c = 4.39e-8;
    WHEN( "max energy of 3eV is used" ){
      maxTauSq = 5.79115688E19; // this corresponds with Emax = 3eV
      imax = hexLatticeFactors( lat, a, c, maxTauSq, b );
      bVec1 = { 2.048475E16, 0.000000000, 2.048475E16, 0.000000000, 8.193901E16, 
                8.230571E-8, 8.193901E16, 8.230571E-8, 1.843628E17, 0.000000000, 
                1.843628E17, 0.000000000, 3.277560E17, 1.641922E-9, 3.277560E17, 
                1.641922E-9, 5.121188E17, 0.000000000, 5.121188E17, 0.000000000, 
                7.374510E17, 2.743524E-8, 7.374510E17, 2.743524E-8, 1.003753E18, 
                9.145859E-7, 1.311024E18, 3.877432E-7, 1.659265E18, 4.404691E-7, 
                2.048475E18, 3.729988E-7, 2.478655E18, 8.901339E-7, 2.949804E18, 
                7.379109E-7, 3.461923E18, 1.979266E-6, 4.015011E18, 1.822562E-6, 
                4.609069E18, 2.077488E-6, 5.244096E18, 2.636050E-6, 5.920093E18, 
                2.831524E-6, 6.637059E18, 3.119091E-6, 7.394995E18, 2.573398E-6, 
                8.193901E18, 2.821574E-6, 9.033775E18, 4.517178E-6, 9.914620E18, 
                3.804797E-6, 1.083643E19, 4.253444E-6, 1.179922E19, 4.878759E-6, 
                1.280297E19, 5.001969E-6, 1.384769E19, 5.440726E-6, 1.493338E19, 
                5.455748E-6, 1.606005E19, 6.349419E-6, 1.722768E19, 7.611619E-6, 
                1.843628E19, 7.764160E-6, 1.968585E19, 8.689601E-6, 2.097639E19, 
                9.577363E-6, 2.230789E19, 9.299183E-6, 2.368037E19, 9.530800E-6, 
                2.509382E19, 9.983057E-6, 2.654824E19, 1.087296E-5, 2.804362E19, 
                1.156476E-5, 2.957998E19, 1.204030E-5, 3.115731E19, 1.300495E-5, 
                3.277560E19, 1.453369E-5, 3.443487E19, 1.349278E-5, 3.787631E19, 
                1.588427E-5, 4.148162E19, 1.683047E-5, 4.525082E19, 1.910801E-5};
      bVec2 = { 4.554968E18, 6.868253E-7, 4.862239E18, 9.006318E-7, 7.013138E18, 
                6.112705E-7, 8.795312E18, 1.515428E-7, 2.077889E19, 4.356922E-7, 
                5.150441E18, 5.947323E-7, 6.297587E18, 2.713179E-8, 8.653333E18, 
                1.312182E-6, 1.055842E19, 2.095396E-8, 1.455294E19, 9.660960E-7, 
                1.957171E19, 3.642029E-7, 2.069837E19, 1.212779E-7, 1.047945E19, 
                8.716691E-7, 1.578500E19, 3.154703E-6, 2.955075E19, 1.425220E-7, 
                1.716200E19, 6.241497E-7, 9.506779E18, 1.129851E-6, 1.042859E19, 
                1.085991E-7, 1.696323E19, 1.234028E-6, 3.107722E19, 5.532361E-7, 
                3.992663E19, 5.468802E-8, 5.596619E19, 5.301305E-7, 1.143998E19, 
                5.458579E-7, 1.568032E19, 7.946192E-7, 1.947000E19, 4.443168E-7, 
                2.649627E19, 3.592087E-7, 3.274412E19, 2.421076E-8, 1.243243E19, 
                5.046843E-7, 1.816816E19, 1.789807E-6, 2.947575E19, 7.875533E-7, 
                1.944896E19, 9.424282E-8, 5.596508E19, 1.507824E-9, 2.342358E19, 
                2.790455E-7, 2.643131E19, 7.796113E-7, 3.982595E19, 1.104109E-6, 
                5.164678E19, 1.141528E-6, 4.358273E19, 4.352579E-7, 4.766499E19, 
                1.405762E-6, 2.174214E17, 1.980764E-7, 7.247378E16, 8.576962E-8, 
                2.379061E17, 0.000000000, 9.295853E16, 7.443884E-8, 2.993604E17, 
                1.722416E-7, 1.544128E17, 5.995614E-8, 4.017841E17, 0.000000000, 
                2.568365E17, 2.341486E-7, 5.451774E17, 5.092358E-9, 4.002298E17, 
                1.485844E-9, 7.295401E17, 0.000000000, 5.845926E17, 1.552006E-7 };
      REQUIRE( imax == 326 );
      checkPartOfVec(b,bVec1,0);
      checkPartOfVec(b,bVec2,300);
      restAreZero(655,b);
    } // WHEN

    WHEN( "max energy of 5eV is used" ){
      maxTauSq = 9.65192813E19; // this corresponds with Emax = 5eV
      imax = hexLatticeFactors( lat, a, c, maxTauSq, b );
      bVec1 = { 2.048475E16, 0.000000000, 2.048475E16, 0.000000000, 8.193901E16, 
                8.230571E-8, 8.193901E16, 8.230571E-8, 1.843628E17, 0.000000000, 
                1.843628E17, 0.000000000, 3.277560E17, 1.641922E-9, 3.277560E17, 
                1.641922E-9, 5.121188E17, 0.000000000, 5.121188E17, 0.000000000, 
                7.374510E17, 2.743524E-8, 7.374510E17, 2.743524E-8, 1.003753E18, 
                9.145859E-7, 1.311024E18, 3.877432E-7, 1.659265E18, 4.404691E-7, 
                2.048475E18, 3.729988E-7, 2.478655E18, 8.901339E-7, 2.949804E18, 
                7.379109E-7, 3.461923E18, 1.979266E-6, 4.015011E18, 1.822562E-6, 
                4.609069E18, 2.077488E-6, 5.244096E18, 2.636050E-6, 5.920093E18, 
                2.831524E-6, 6.637059E18, 3.119091E-6, 7.394995E18, 2.573398E-6, 
                8.193901E18, 2.821574E-6, 9.033775E18, 4.517178E-6, 9.914620E18, 
                3.804797E-6, 1.083643E19, 4.253444E-6, 1.179922E19, 4.878759E-6, 
                1.280297E19, 5.001969E-6, 1.384769E19, 5.440726E-6, 1.493338E19, 
                5.455748E-6, 1.606005E19, 6.349419E-6, 1.722768E19, 7.611619E-6, 
                1.843628E19, 7.764160E-6, 1.968585E19, 8.689601E-6, 2.097639E19, 
                9.577363E-6, 2.230789E19, 9.299183E-6, 2.368037E19, 9.530800E-6, 
                2.509382E19, 9.983057E-6, 2.654824E19, 1.087296E-5, 2.804362E19, 
                1.156476E-5, 2.957998E19, 1.204030E-5, 3.115731E19, 1.300495E-5, 
                3.277560E19, 1.453369E-5, 3.443487E19, 1.349278E-5, 3.787631E19, 
                1.588427E-5, 4.148162E19, 1.683047E-5, 4.525082E19, 1.910801E-5}; 
      bVec2 = { 4.290499E18, 2.400732E-7, 5.826856E18, 6.594154E-7, 7.055941E18, 
                6.064108E-8, 1.461481E19, 2.783781E-6, 8.055523E19, 5.531787E-6, 
                8.571739E19, 6.893173E-6, 9.104342E19, 7.274640E-6, 2.609056E18, 
                7.697297E-7, 2.936812E18, 6.582199E-9, 3.121175E18, 0.000000000, 
                4.268321E18, 4.465106E-7, 1.344549E19, 1.956422E-7, 2.491695E19, 
                2.143852E-6, 5.179294E19, 6.302740E-7, 4.554968E18, 6.868253E-7, 
                4.862239E18, 9.006318E-7, 7.013138E18, 6.112705E-7, 8.795312E18, 
                1.515428E-7, 2.077889E19, 4.356922E-7, 5.150441E18, 5.947323E-7, 
                6.297587E18, 2.713179E-8, 8.653333E18, 1.312182E-6, 1.055842E19, 
                2.095396E-8, 1.455294E19, 9.660960E-7, 1.957171E19, 3.642029E-7, 
                2.069837E19, 1.212779E-7, 1.047945E19, 8.716691E-7, 1.578500E19, 
                3.154703E-6, 2.955075E19, 1.425220E-7, 1.716200E19, 6.241497E-7, 
                6.052822E19, 2.534996E-6, 9.506779E18, 1.129851E-6, 1.042859E19, 
                1.085991E-7, 1.696323E19, 1.234028E-6, 3.107722E19, 5.532361E-7, 
                3.992663E19, 5.468802E-8, 5.596619E19, 5.301305E-7, 8.007675E19, 
                4.408307E-6, 1.143998E19, 5.458579E-7, 1.568032E19, 7.946192E-7, 
                1.947000E19, 4.443168E-7, 2.649627E19, 3.592087E-7, 3.274412E19, 
                2.421076E-8, 1.243243E19, 5.046843E-7, 1.816816E19, 1.789807E-6, 
                2.947575E19, 7.875533E-7, 9.099145E19, 4.423966E-7, 1.944896E19, 
                9.424282E-8, 8.551228E19, 1.370173E-6, 5.596508E19, 1.507824E-9};
      REQUIRE( imax == 368 );
      checkPartOfVec(b,bVec1,0);
      checkPartOfVec(b,bVec2,300);
      restAreZero(738,b);
    } // WHEN
  } // GIVEN


} // TEST CASE

